package com.example.shop_car_2208.detail


import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.shop_car_2208.entity.*
import com.example.shop_car_2208.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class DetailViewModel:BaseViewModel() {
    val detailSuccess = MutableLiveData<DetailResult>()
    val detailFail = MutableLiveData<String>()
    fun cateIl(id:Int){
        viewModelScope.launch {
            try {
                detailSuccess.value = apiService.getDetail(id)
            }catch (e:Exception){
                detailFail.value = e.message
            }
        }
    }

    val addSuccess = MutableLiveData<AddCarResult>()
    val addFail = MutableLiveData<String>()
    fun AddCar(id:Int,count:Int){
        viewModelScope.launch {
            try {
                val param = AddCarParam(count,id)
                addSuccess.value = apiService.getAddCar(param)
            }catch (e:Exception){
                addFail.value = e.message
            }
        }
    }


}